package com.lhg.common.util;

import cn.hutool.core.codec.Base64;
import cn.hutool.crypto.SecureUtil;
import cn.hutool.crypto.symmetric.SymmetricAlgorithm;
import cn.hutool.crypto.symmetric.SymmetricCrypto;

import java.nio.charset.Charset;

/**
 * @author fangzc
 * @date 2018/11/29 16:07
 */
public class SoftdogUtil {
    /**
     * 创建解压密码
     *
     * @param machineSerialNum
     * @return
     */
    public static String createUnZipPwd(String machineSerialNum) {
        //随机生成密钥
        byte[] key = SecureUtil.generateKey(SymmetricAlgorithm.AES.getValue()).getEncoded();
        //构建
        SymmetricCrypto aes = new SymmetricCrypto(SymmetricAlgorithm.AES, key);
        //加密为16进制表示
        String encryptHex = aes.encryptHex(machineSerialNum);
        String unzipPwd = Base64.encode(encryptHex, Charset.defaultCharset());
        return unzipPwd;
    }
}
